<?php
require_once("../DAO/UserDAO.php");
include_once("../Utility/WebSession.php");
include_once("../DAO/TestDAO.php");
include_once("../Entities/Test.php");
include_once("../Utility/WebUtilities.php");

$testDAO = new TestDAO();
if(WebUtilities::GetQueryString("btSubmit", "") != "")
{
	$test = $testDAO->GetTestById(WebUtilities::GetQueryString("cbTest", -1));
	if($test != null)
	{
		WebSession::SetSession("TestSession", $test);
		WebSession::SetSession("CurrentQuestion", 0);
		WebSession::SetSession("TestType", WebUtilities::GetQueryString("rbType", 0));
		WebUtilities::Redirect("UserTesting.php");
	}
}

$type = WebUtilities::GetQueryString("type", 0);
$tests = $testDAO->GetAll();
$optionStr = "";
for($i = 0 ; $i < count($tests); $i++)
{
	$optionStr = $optionStr . "<option value='" . $tests[$i]->Id . "'>" . $tests[$i]->Name . "</option>";
}

$mainContent = "<form enctype='multipart/form-data' action='MainTest.php' method='POST'>
					<h2>Choose the test you want</h2>
					<div class='oneLine'>
						<div class='left'>Test Name</div>
						<select class='right' name='cbTest' onchange='ChooseTest(this.value)'>
							" . $optionStr . "
						</select>
					</div>
					<div class='oneLine'>
						<div class='left'>Type</div>
						<input type='radio' name='rbType' value='0' " . ($type == 0 ? "checked" : "") . " >Training</input>
						<input type='radio' name='rbType' value='1' " . ($type == 1 ? "checked" : "") . " >Practice Test</input>
					</div>
					<div class='oneLine' id='divDescription'>
						<div class='left'>Description</div>
						<textarea id='tbDes' readonly='true' style='width:300px;height:200px;overflow:auto;'>" . 
						(count($tests) > 0 ? $tests[0]->Description : "") . "</textarea>
					</div>
					<div class='oneLine'>
						<div class='left'>&nbsp;</div>
						<input type='submit' value='Start' name='btSubmit' />
						<input type='button' value='Cancel' onclick=\"window.location='index.php'\" />
					</div>
				</form>";
$pageIndex = 2;
include("MasterPage.php");
?>